frontend/pages/e/[uuid]/index.tsx (view raw)
1import {PropsWithChildren} from 'react';
2import TravelColumns from '../../../containers/TravelColumns';
3import pageUtils from '../../../lib/pageUtils';
4import EventLayout from '../../../layouts/Event';
5import {EventByUuidDocument} from '../../../generated/graphql';
6import {getLocaleForLang} from '../../../lib/getLocale';
7
8interface Props {
9 eventUUID: string;
10 announcement?: string;
11}
12
13const Page = (props: PropsWithChildren<Props>) => {
14 return <EventLayout {...props} Tab={TravelColumns} />;
15};
16
17export const getServerSideProps = pageUtils.getServerSideProps(
18 async (context, apolloClient) => {
19 const {uuid} = context.query;
20 const {host = ''} = context.req.headers;
21 let event = null;
22
23 // Fetch event
24 try {
25 const {data} = await apolloClient.query({
26 query: EventByUuidDocument,
27 variables: {uuid},
28 });
29 event = data?.eventByUUID?.data;
30 } catch (error) {
31 return {
32 notFound: true,
33 };
34 }
35
36 const description = await getLocaleForLang(
37 event?.attributes?.lang,
38 'meta.description'
39 );
40
41 return {
42 props: {
43 eventUUID: uuid,
44 metas: {
45 title: event?.attributes?.name || '',
46 description,
47 url: `https://${host}${context.resolvedUrl}`,
48 },
49 },
50 };
51 }
52);
53
54export default Page;